﻿Imports System
Imports System.IO
Imports System.Data.SqlServerCe
Imports System.Drawing
Imports System.Collections
Imports System.Windows.Forms
Imports System.Data
Imports System.Data.Common

Module DatatableService

    Public Sub findAcceptRejectWeldLogForListing(ByVal barcode As String, ByVal updateDate As String, ByVal status As String, ByVal lv As System.Windows.Forms.ListView)
        Dim dtResult As New DataTable
        Dim paramList As New Hashtable()
        Dim lstView As New ListViewItem

        dtResult = findAcceptRejectWeldLogs(barcode, updateDate, status)

        lv.Items.Clear()
        If dtResult.Rows.Count > 0 Then
            For Each dataRow As DataRow In dtResult.Rows
                lstView = lv.Items.Add(New ListViewItem(dataRow.Item("BARCODE").ToString))
                lstView.SubItems.Add(dataRow.Item("SEQ").ToString)
                lstView.SubItems.Add(dataRow.Item("SYSTEM_TYPE_NAME").ToString)
                lstView.SubItems.Add(dataRow.Item("HEAT_NUMBER_NAME_1").ToString & "-" & dataRow.Item("HEAT_NUMBER_NAME_2").ToString)
                lstView.SubItems.Add(dataRow.Item("JOINT_TYPE_NAME_1").ToString & "-" & dataRow.Item("JOINT_TYPE_NAME_2").ToString)
                lstView.SubItems.Add(dataRow.Item("MATERIAL").ToString & "-" & dataRow.Item("SIZE").ToString & "-" & dataRow.Item("THICKNESS").ToString)
                
                lstView.Tag = dataRow.Item("BARCODE")
            Next
        End If
    End Sub

    Public Sub findCouponForListing(ByVal couponDate As String, ByVal couponNo As String, ByVal status As String, ByVal barcode As String, ByVal couponInOut As String, ByVal lv As System.Windows.Forms.ListView)
        Dim dtResult As New DataTable
        Dim paramList As New Hashtable()
        Dim lstView As New ListViewItem

        dtResult = findEngineerCoupons(_PROJECT_ID, couponDate, couponNo, status, vbNullString, barcode, couponInOut)

        lv.Items.Clear()
        If dtResult.Rows.Count > 0 Then
            For Each dataRow As DataRow In dtResult.Rows
                Dim couponCode As String = dataRow.Item("COUPON_CODE")
                Dim couponType As String = dataRow.Item("COUPON_TYPE")

                lstView = lv.Items.Add(New ListViewItem(couponCode & "-" & couponType))
                lstView.SubItems.Add(dataRow.Item("USER_NAME").ToString)
                lstView.SubItems.Add(dataRow.Item("MATERIAL").ToString & "-" & dataRow.Item("SIZE").ToString & "-" & dataRow.Item("THICKNESS").ToString)
                lstView.SubItems.Add(dataRow.Item("STATUS_CODE").ToString)
                lstView.SubItems.Add(dataRow.Item("DATE_ADD").ToString & "-" & dataRow.Item("TIME_ADD").ToString)

                If (dataRow.Item("WELD_COUNT") Is Nothing) Then
                    lstView.SubItems.Add(0)
                Else
                    lstView.SubItems.Add(dataRow.Item("WELD_COUNT").ToString)
                End If


                '''''''''''''''''''''''''''''''
                Dim couponSystemDtResult As New DataTable
                Dim systemString As String = ""

                couponSystemDtResult = findCouponSystems(couponNo)

                If couponSystemDtResult.Rows.Count > 0 Then
                    For Each couponSystemDataRow As DataRow In couponSystemDtResult.Rows
                        If (systemString <> "") Then
                            systemString &= ","
                        End If

                        systemString &= couponSystemDataRow.Item("SYSTEM_TYPE_NAME")
                    Next
                End If
                ''''''''''''''''''''''''''''''
                lstView.SubItems.Add(systemString)
                lstView.SubItems.Add(dataRow.Item("COAX").ToString)

                If (dataRow.Item("REMARKS") Is Nothing Or dataRow.Item("REMARKS") = "") Then
                    lstView.SubItems.Add("")
                Else
                    lstView.SubItems.Add(dataRow.Item("REMARKS").ToString)
                End If

                lstView.Tag = dataRow.Item("COUPON_ID")
            Next
        End If
    End Sub

    Public Function findSystemTypeForListing(ByVal lv As System.Windows.Forms.ListView) As System.Windows.Forms.ListView
        Dim dtResult As New DataTable
        Dim lstViewCust As New ListViewItem

        dtResult = findSystemTypes(_PROJECT_ID, Nothing)
        lv.Items.Clear()

        If dtResult.Rows.Count > 0 Then
            For Each dataRow As DataRow In dtResult.Rows
                lstViewCust = lv.Items.Add(New ListViewItem(dataRow.Item("SYSTEM_TYPE_NAME").ToString))
                lstViewCust.SubItems.Add(dataRow.Item("DRAWING_NUMBER").ToString)
                'lstViewCust.SubItems.Add(dataRow.Item("STATUS_CODE")))
                lstViewCust.Tag = dataRow.Item("SYSTEM_TYPE_ID").ToString
            Next
        End If

        Return lv
    End Function
End Module
